package com.augurit.gzcgwsp.state.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import com.augurit.common.util.PageUtils;
import com.augurit.gzcgwsp.state.service.IYwZhengwuNotBjService;
import com.augurit.gzcgwsp.webservice.dao.ExChangeDataDao;
import com.augurit.gzcgwsp.wfex.bi.web.form.WfBusInstanceFormEX;
import com.augurit.wf.common.service.impl.WfBusClientServiceImpl;

@Service
@Transactional
public class YwZhengwuNotBjServiceImpl extends WfBusClientServiceImpl<WfBusInstanceFormEX>  implements IYwZhengwuNotBjService {
	Logger logger = (Logger) LoggerFactory.getLogger(YwZhengwuNotBjServiceImpl.class);
	private static final  ExChangeDataDao ExChangeDataDao=new ExChangeDataDao();

	@Override
	public Page<WfBusInstanceFormEX> search(Page<WfBusInstanceFormEX> page,
			List<PropertyFilter> filters) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<WfBusInstanceFormEX> search(Page<WfBusInstanceFormEX> page,
			WfBusInstanceFormEX form) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void delete(Long... ids) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public WfBusInstanceFormEX get(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void save(WfBusInstanceFormEX... forms) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void save(WfBusInstanceFormEX forms) {
		// TODO Auto-generated method stub
		
	}
	
	public Page<WfBusInstanceFormEX> searchPage(Page<WfBusInstanceFormEX> page,Map map) {
		StringBuffer sb = new StringBuffer();
		sb.append(" select to_char(jhp.process_duedate, 'YYYY-MM-DD HH24:mi:ss') process_duedate, t.*");
		sb.append(" from WF_BUS_INSTANCE t, JBPM4_HIST_PROCINST jhp");
		sb.append(" where t.proc_inst_id = jhp.id_ and t.bus_memo3 in");
		sb.append(" (select distinct a.serial_No from YW_ZHENGWU_INFO a,");
		sb.append(" (select distinct t.serial_No from YW_ZHENGWU_INFO t) t1");
		sb.append(" where t1.serial_No = a.serial_No and not exists ");
		sb.append(" (select * from YW_ZHENGWU_INFO b");
		sb.append(" where b.sphjdm = '005' and b.serial_No = t1.serial_No))");
		sb.append(" order by jhp.process_duedate asc");
		Map paraMap=new HashMap(); 
		Page pg = PageUtils.newPageInstance(page);
//		this.wfBusInstanceDao.findPage(pg, sb.toString(),paraMap);
		List list0 = ExChangeDataDao.searchByPage(sb.toString(), pg, paraMap);
		Long totalCount=ExChangeDataDao.getTotalCount(sb.toString());
		pg.setTotalCount(totalCount);
		List wfBusInstanceFormEXList = new ArrayList();
		if(list0 != null && list0.size()>0){
			for(int i = 0;i<list0.size();i++){
				Map map0=(Map) list0.get(i);
				WfBusInstanceFormEX form = new WfBusInstanceFormEX();
				form.setMasterEntityKey((String)(map0.get("master_entity_key")));
				form.setBusMemo1((String)(map0.get("bus_memo1")));
				form.setBusMemo3((String)(map0.get("bus_memo3")));
				form.setBusMemo4((String)(map0.get("bus_memo4")));
				form.setProcessDuedate((String)(map0.get("process_duedate")));
				wfBusInstanceFormEXList.add(form);
			}
		}
		// 建立新的分页对象		
//		List<WfBusInstanceFormEX> list = YwZhengwuNotBjConvert.convertVoListToFormList(list0);
//		pg.setResult(wfBusInstanceFormEXList);
		PageUtils.copy(pg, wfBusInstanceFormEXList, page);
//		page.setResult(wfBusInstanceFormEXList);
		return page;
	}

}
